package com.ky.serialport.sensor;

import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

import static com.ky.serialport.utils.RandomUtils.myRandom;

/**
 * GYD50W矿用本安型无线电压变送器 ACK
 * */
public class DianYaBianSongQiAckBean {

    public byte[] bRec;
    public Long time;
    public int power; // 电量
    public int signal; //信号
    public ComBean comBean;

    public DianYaBianSongQiAckBean() {

    }

    public DianYaBianSongQiAckBean(ComBean comBean ) {
        time = comBean.recTime;
        this.comBean = comBean;
        caculate(comBean.recData);
    }

    public DianYaBianSongQiAckBean(byte[] recData) {
        caculate(recData);
        time = System.currentTimeMillis();
    }

    public DianYaBianSongQiAckBean caculate(ComBean comBean){
        time = comBean.recTime;
        this.comBean = comBean;
        return caculate(comBean.recData);
    }

    public DianYaBianSongQiAckBean caculate(byte[] bRec) {
        power = MyFunc.getPower(bRec[12],bRec[13]);
        signal = MyFunc.getSignal(bRec[14]);
        this.bRec = bRec;
        return this;
    }

    public DianYaBianSongQiAckBean test() {
        time = System.currentTimeMillis();
        power = 300 + myRandom.nextInt(120);
        signal = 200;
        return this;
    }

}
